package cn.indi.zyj.member.test;

import cn.indi.zyj.common.resp.CommonResp;
import cn.indi.zyj.member.req.MemberLoginReq;
import cn.indi.zyj.member.req.MemberRegisterReq;
import cn.indi.zyj.member.req.MemberSendCodeReq;
import cn.indi.zyj.member.resp.MemberLoginResp;
import cn.indi.zyj.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {


    @Resource
    private MemberService memberService;


    @GetMapping("/count")
    public CommonResp<Integer> count(){
        return new CommonResp<>(memberService.count());
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRegisterReq registerReq){
        return new CommonResp<>(memberService.register(registerReq));
    }

    @PostMapping("/sendCode")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq memberSendCodeReq){
        memberService.memberSendCode(memberSendCodeReq);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq memberLoginReq){

        return new CommonResp<>(memberService.login(memberLoginReq));
    }

}
